<template>
	<view class="teacherdetail padding">
		<view class="cu-list menu-avatar" >
			<view class="cu-item">
				<view class="cu-avatar round lg">
					<image :src="teachInfoLi.image_url" mode="" style="width: 100rpx;height: 100rpx;border-radius: 50%;"></image>
				</view>
				<view class="content">
					<view class="text-grey">
						<view class="text-cut">{{teachInfoLi.name}}</view>
						<view class="cu-tag round bg-orange sm">讲师</view>
					</view>
					<view class="text-gray text-sm flex">
						<view class="text-cut">
							{{teachInfoLi.desc}}
						</view>
					</view>
				</view>
				<view class="action" style="width: 140rpx;">
					<text class="bg-green text-xs" style="padding: 12rpx 24rpx;border-radius: 18rpx;" @click="doesAttention">
						{{textLike}}
					</text>
				</view>
			</view>
		</view>
		<h3 class="margin-top">他的课程</h3>
		<view class="publicLesson margin-top">
			<view class="publicContent">
				<view class="content_one" v-for="item in teachClassList" :key="item.id" @click="gotovideodetail(item.id)">
					<image :src="item.image_url" mode=""></image>
					<view class="others">
						<h3>{{item.name}}</h3>
						<text style="font-size: 26rpx;">教师:{{item.teacher_name}}</text>
						<uni-rate v-model="item.grade" :readonly="true" :is-fill="false" :max="5" allow-half :size="16"/>
						<view class="content_oneBottom">
							<text style="font-size: 26rpx;margin-top: 6rpx;">{{item.add_time}}</text>
							<view class="bottom_right">
								<text class="lg text-gray cuIcon-attentionfavor">{{item.click_nums}}</text>
								<text class="lg text-gray cuIcon-appreciate">{{item.give_like_nums}}</text>
							</view>
						</view>
					</view>
				</view>
			</view>
			<view v-if="isover" class="b_bottom text-center" style="padding-bottom: 20rpx;">
				----已经到底了-----
			</view>
		</view>
	</view>
</template>

<script>
	export default{
		data() {
			return {
				id:0,
				teachInfoLi:[],
				textLike:'',
				teachClassList:[],
				isover:false,
				page:1,
				total:0,
			}
		},
		onLoad(option) {
			this.id = option.id
			this.getTeacherInfo()
			this.getTeachersLessonAll()
		},
		methods:{
			async getTeacherInfo(){
				let res = await this.$myRuquest({
					url:`/detail_teachers/${this.id}/`
				})
				this.teachInfoLi = res.data
				if(this.teachInfoLi.is_attention_teacher==true){
					this.textLike = '已关注'
				}else{
					this.textLike = '+关注'
				}
			},
			async doesAttention(){
				let res = await this.$myRuquest({
					url:`/click_teacher/${this.id}/`,
					method:'POST'
				})
				if(res.data.msg=='取消关注成功'){
					this.textLike = '+关注'
					uni.showToast({
						title:'已取消关注'
					})
				}else if(res.data.msg=='关注成功'){
					this.textLike = '已关注'
					uni.showToast({
						title:'已关注'
					})
				}
			},
			async getTeachersLessonAll(){
				let page = this.page
				let res = await this.$myRuquest({
					url:`/teacher_courses/?page=${page}`,
					data:{teacher_id:this.id}
				})
				this.teachClassList = [...this.teachClassList,...res.data.results]
				this.total = res.data.count
			},
			gotovideodetail(id){
				uni.navigateTo({
				    url: `../videodetail/videodetail?id=${id}`
				});
			},
			onReachBottom() {
				if(this.teachClassList.length>=this.total) return this.isover = true
				this.page++
				this.getTeachersLessonAll()
			},
		}
	}
</script>

<style lang="scss">
.teacherdetail{
	.publicLesson{
		.publicContent{
			padding: 10rpx 10rpx;
			.content_one{
				display: flex;
				padding: 30rpx 30rpx;
				margin-bottom: 20rpx;
				background: white;
				border-radius: 20rpx;
				image{
					width: 185rpx;
					height: 132rpx;
					border-radius: 15rpx;
				}
				.others{
					width: 565rpx;
					height: 132rpx;
					padding-left: 30rpx;
					display: flex;
					justify-content: space-between;
					flex-direction: column;
					.content_oneBottom{
						display: flex;
						justify-content: space-between;
						.bottom_right{
							padding-left: 50rpx;
						}
					}
				}
			}
		}
	}
}
</style>
